import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
  Logger,
  UseInterceptors,
} from '@nestjs/common';

import { RchyService } from './rchy.service';
import { CreateRchyDto } from './dto/create-rchy.dto';
import { UpdateRchyDto } from './dto/update-rchy.dto';
import { TransformInterceptor } from 'src/core/interceptor/transform/transform.interceptor';
import { ContactDto } from './dto/rchy.dto';
import { plainToInstance } from 'class-transformer';
import { ApiOperation } from '@nestjs/swagger';

@Controller('api/rchy')
@UseInterceptors(TransformInterceptor)
export class RchyController {
  constructor(private readonly rchyService: RchyService) {}
  private readonly l = new Logger(RchyController.name);

  @ApiOperation({ description: '说明方法的用途、作用' })
  @Get('getContact')
  getContact() {
    return this.rchyService.getContact();
  }

  // old
  @Post()
  create(@Body() createRchyDto: CreateRchyDto) {
    return this.rchyService.create(createRchyDto);
  }

  @Get()
  findAll(@Query() param: CreateRchyDto) {
    this.l.log(param);
    const a = plainToInstance(ContactDto, {
      _id: '5fe1bafe64635100014b6684',
      create_time: 1608628990117,
      status: 0,
      name: '御珍坊',
      wechat: 'liuzhiqiang037907',
      phone: '15802028678',
      letter: 'Y',
      uid: '5fcefacd974b69000118c8fa',
    });
    return a;
    // return this.rchyService.findAll();
  }

  @Get(':id')
  findOne(@Param('id') id: string) {
    return this.rchyService.findOne(+id);
  }

  @Patch(':id')
  update(@Param('id') id: string, @Body() updateRchyDto: UpdateRchyDto) {
    return this.rchyService.update(+id, updateRchyDto);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.rchyService.remove(+id);
  }
}
